package com.duanjw.springframework.beanpostprocessor;

import com.duanjw.springframework.beanpostprocessor.config.AppConfig;
import com.duanjw.springframework.beanpostprocessor.dao.impl.UserDaoImpl;
import com.duanjw.springframework.beanpostprocessor.service.UserService;
import com.duanjw.springframework.beanpostprocessor.service.impl.UserServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 通过注解方式实例化容器，并使用容器
 *
 * @author duanjw
 */
public class PostProcessorApplication {
    public static void main(String[] args) {
        // 一、通过读取XML实例化容器，并使用容器

        // 1. spring.xml配置元数据文件中引入了services.xml和daos.xml，所以可以直接引入spring.xml
        // ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("xml/spring.xml");

        // 2. 也可以一次引入多个配置元数据文件
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        ctx.register(AppConfig.class);
//        ctx.register(TestAutowireMode.class);
        ctx.refresh();
        UserService userService = (UserService) ctx.getBean("userServiceImpl");
//      ctx.getBean(UserDaoImpl.class);
//        UserService userService1 = ctx.getBean(UserServiceImpl.class);
//        UserService userService2 = ctx.getBean(UserServiceImpl2.class);
        userService.query();
//        userService1.query();
//        userService2.query();

    }
}
